import random


def monty_hall_simulation(num_simulations=1000):
    win_with_switch = 0
    win_without_switch = 0
    for _ in range(num_simulations):
        car = random.randint(0, 2)
        choice = random.randint(0, 2)
        doors = [0, 1, 2]
        can_open = [d for d in doors if d != car and d != choice]
        opened = random.choice(can_open)
        swiched_choice = [d for d in doors if d != choice and d != opened][0]
        if choice == car:
            win_without_switch += 1
        if swiched_choice == car:
            win_with_switch += 1

    print(f"模拟次数:{num_simulations}")
    print(f"换门获胜的概率:{win_with_switch / num_simulations}")
    print(f"不换门获胜的概率:{win_without_switch / num_simulations}")


monty_hall_simulation()

